package com.yogurt.vod.controller;

import com.yogurt.utils.Result;
import com.yogurt.vod.service.VodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Auther: 酸奶
 * @Date: 2020/08/26 20:42
 * @Description: 上传视频的controller
 */

@RestController
@RequestMapping("/eduvod/video")
@CrossOrigin
public class VodController {

    @Autowired
    private VodService vodService;

    //上传视频到阿里云
    @PostMapping("/uploadVideo")
    public Result uploadVideo(MultipartFile file){
        //得到上传成功后的视频id
        String videoId = vodService.uploadVideo(file);
        if(videoId == null){
            return Result.error();
        }
        return Result.ok().data("videoId",videoId);
    }

    //根据视频id删除阿里云中的视频(单个删除)
    @DeleteMapping("/deleteVideo/{id}")
    public Result deleteVideo(@PathVariable String id){
        boolean flag = vodService.deleteVideo(id);
        if (!flag){
            return Result.error();
        }
        return Result.ok();
    }

    //根据视频id删除阿里云中的视频(批量删除)
    @DeleteMapping("/deleteBatchVideo")
    public Result deleteBatchVideo(@RequestParam("ids") List<String> ids) {
        boolean flag = vodService.deleteBatchVideo(ids);
        if (!flag){
            return Result.error();
        }
        return Result.ok();
    }
}
